package com.tao.controller;


import com.tao.dto.MyResult;
import com.tao.dto.PageResult;
import com.tao.dto.SuccessResult;
import com.tao.entity.Member;
import com.tao.entity.User;
import com.tao.service.MemberService;
import com.tao.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value="会员controller",tags={"会员"})
@RestController
@CrossOrigin
public class MemberController {

    @Autowired
    MemberService memberService;


    @ApiOperation("会员登录")
    @PostMapping("/member/login")
    public MyResult login(@RequestBody Member member){
        return memberService.login(member);
    }

    @ApiOperation("会员注册")
    @PostMapping("/member/register")
    public MyResult register(@RequestBody Member member){
        return memberService.register(member);
    }

    @ApiOperation("会员增加")
    @PostMapping("/member/add")
    public MyResult add(@RequestBody Member member){
        Member insert = memberService.insert(member);
        return new SuccessResult("操作成功",insert);
    }

    @ApiOperation("会员获取")
    @GetMapping("/member/getALL")
    public MyResult getAll( Integer page,Integer size,Member member){
        PageResult all = memberService.findAll(member, page, size);
        return new SuccessResult("获取成功",all);
    }

    @ApiOperation("会员删除")
    @DeleteMapping("/member/del/{id}")
    public MyResult del(@PathVariable("id") Integer id){
         memberService.delete(id);
        return new SuccessResult("删除成功",null);
    }




}
